Page Counter Component

The Page Counter component counts and displays the number of times a Web page has been opened. At regular intervals it writes the number of hits to a text file so that in the event of a server shutdown, the data is not lost. The Page Counter component uses an internal Central Management object to record how many times each page in the application has been opened.

When an instance of the Page Counter component is created on a page by using the Server.CreateObject method, the component retrieves the current hit count for the specified Web page from the Central Management object.

Note This component is not officially supported by Microsoft® Corporation. Peer support is available on the Active Server Pages mailing list or on the microsoft.public.inetserver.iis.activeserverpages newsgroup.

To subscribe to the Active Server Pages mailing list, send e-mail to listserv@listserv.msn.com with

subscribe ActiveServerPages [firstname lastname]

in the body of the message, and then follow the directions carefully. (Firstname and lastname are optional.)

You can reach the newsgroup through msnews.microsoft.com and other NNTP servers.

The Page Counter component uses the following files:

File Names
PageCnt.dll The Page Counter component.
Hit Count Data file The text file to which the Page Counter component saves the current hit count.


Syntax

<% Set oVar = Server.CreateObject("IISSample.PageCounter") %>

Registry Entries

The Page Counter adds the key IISSample.PageCounter to the registry when the component is compiled or registered. The key is added under HKEY_CLASSES_ROOT and contains the following named values:

Named Value Description
File_Location A string that specifies the path and filename of the Hit Count Data file. The default filename is Hitcnt.cnt. This file is located in your Windows directory.
Save_Count A DWORD that specifies the number of hits before the hit count is saved to the Hit Count Data file. Note that this is the total number of hits, not the number of hits per page. The default value is 25.


Methods
Hits Displays the number of times that a specified URL has been opened.
Reset Sets the hit count for a specified page to 0.


Example

The following example uses the Page Counter component to track the number of visitors to the page and sends a special message to the millionth visitor.
<% 
Set MyPageCounter = Server.CreateObject("IISSample.PageCounter")
HitMe = MyPageCounter.Hits

If HitMe = 1000000 Then 
%>
  You are the lucky 1,000,000th Customer!!! <BR>
<% Else %>
  Sorry, you are customer #<%= HitMe %> <BR>
<% End If %>